package com.lanqiao.guimei.controller;

import com.lanqiao.guimei.dao.TradeDetailDao;
import com.lanqiao.guimei.vo.TradeDetail;
import com.lanqiao.web.mvc.annotation.Controller;
import com.lanqiao.web.mvc.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:沈林玉
 * @date:2019/8/15 10:28
 * @Description:
 */
@Controller
public class TradeDetailController {
    TradeDetailDao tradeDetailDao = new TradeDetailDao();

    /**
     * 1.交易量
     * @param session
     * @param tradeDetail
     * @return
     */
    @RequestMapping("/select/trade")
    public String selectMonthTrade(HttpServletRequest request,HttpSession session, TradeDetail tradeDetail){
        List<TradeDetail> tradeMonthDetails = tradeDetailDao.selectMonthTradeVolume(tradeDetail);
        int m[] =new int[13];
        if (tradeMonthDetails!=null){
            for (TradeDetail tradeDetail1:tradeMonthDetails){
                m[Integer.valueOf(tradeDetail1.getTrd_month().substring(0,2))-1]+=tradeDetail1.getMonth_quantity();
            }
        }
        request.setAttribute("tradeMonthDetails",m);

        List<TradeDetail> tradeQuarterDetails = tradeDetailDao.selectQuarterTradeVolume(tradeDetail);
        int q[] =new int[5];
        if (tradeQuarterDetails!=null){
            for (TradeDetail tradeDetail1:tradeQuarterDetails){
                q[Integer.valueOf(tradeDetail1.getTrd_quarter())-1]+=tradeDetail1.getQuarter_quantity();
            }

        }
        request.setAttribute("tradeQuarterDetails",q);

        List<TradeDetail> tradeYearDetails = tradeDetailDao.selectYearTradeVolume(tradeDetail);
        if (tradeYearDetails!=null){
            session.setAttribute("tradeYearDetails",tradeYearDetails);
        }
        return "/after/volume.jsp";
    }

    /**
     * 2.季度交易量
     * @param session
     * @param tradeDetail
     * @return
     */
    @RequestMapping("/select/quarterTrade")
    public String selectquarterTrade(HttpSession session,TradeDetail tradeDetail){
        List<TradeDetail> tradeDetails = tradeDetailDao.selectQuarterTradeVolume(tradeDetail);
        if (tradeDetails!=null){
            session.setAttribute("tradeQuarterDetails",tradeDetails);
            return "/after/volume.jsp";
        }
        return null;
    }
    /**
     * 2.年度交易量
     * @param session
     * @param tradeDetail
     * @return
     */
    @RequestMapping("/select/yearTrade")
    public String selectYearTrade(HttpSession session,TradeDetail tradeDetail){
        List<TradeDetail> tradeDetails = tradeDetailDao.selectYearTradeVolume(tradeDetail);
        if (tradeDetails!=null){
            session.setAttribute("tradeYearDetails",tradeDetails);
            return "/after/volume.jsp";
        }
        return null;
    }


}
